package jp.cane.android.luciferblue;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class CpmFragment extends Fragment {
	private Handler handler = new Handler();

	// 取得したServiceの保存
	private MainService mBoundService = null;

	private View view = null;

	public void setService(MainService boundService) {
		this.mBoundService = boundService;
		updateView();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		this.view = inflater.inflate(R.layout.cpm, null);

		return this.view;
	}

	public void updateView() {
		if (view == null) {
			return;
		}
		TextView text = (TextView) view.findViewById(R.id.cpm);
		text.setText("" + (mBoundService.getThread().countList.size() / 5));
	}

	public void change(String str) {
		this.handler.post(new Runnable() {
			public void run() {
				updateView();
			}
		});
	}
}
